import { useIntersectionObserver } from "@vueuse/core";

export const lazyPlugin = {
  install(app) {
    app.directive("img-lazy", {
      mounted(el, binding) {
        const { stop } = useIntersectionObserver(
          el,
          ([entry], observerElement) => {
            if (entry?.isIntersecting || false) {
              el.src = binding.value;
              stop();
            }
          }
        );
      },
    });
  },
};
